package com.zhq.wx.controller;

import com.zhq.bean.Express;
import com.zhq.bean.Message;
import com.zhq.bean.User;
import com.zhq.mvc.ResponseBody;
import com.zhq.service.CourierService;
import com.zhq.service.ExpressService;
import com.zhq.util.JSONUtil;
import com.zhq.util.UserUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:钟豪强
 * @Description:
 * @Date Created in  2020-08-22 23:12
 * @Modified By:
 */
public class CourierController {

    @ResponseBody("/wx/courierAddExpress.do")
    public String courierAddExpress(HttpServletRequest request, HttpServletResponse response){
        System.out.println("收到");
        String number = request.getParameter("number");
        String username = request.getParameter("username");
        String phone = request.getParameter("phone");
        String company = request.getParameter("company");
        User wxUser = UserUtil.getWxUser(request.getSession());
        System.out.println(wxUser);
        Express express = new Express();
        express.setNumber(number);
        express.setUsername(username);
        express.setUserPhone(phone);
        express.setCompany(company);
        express.setSysPhone(wxUser.getUserPhone());
        boolean flag = ExpressService.insert(express);
        Message msg = new Message();
        if (flag) {
            msg.setStatus(0);
            msg.setResult("录入成功");
        }else{
            msg.setStatus(-1);
            msg.setResult("录入失败");
        }
        return JSONUtil.toJSON(msg);
    }

    // @ResponseBody("/ul/indexQueryExpress")
    // public String findExpressByNumber(HttpServletRequest request, HttpServletResponse response) {
    //     String expressNum = request.getParameter("expressNum");
    //     Express express = ExpressService.findByNumber(expressNum);
    //     Message msg = new Message();
    //     if (express != null) {
    //         msg.setStatus(0);
    //         msg.setData(msg);
    //     }else{
    //         msg.setStatus(-1);
    //         msg.setResult("录入失败");
    //     }
    //     return JSONUtil.toJSON(msg);
    // }
}
